package com.zzzzzz.account.dao;

import com.google.code.morphia.Morphia;
import com.google.code.morphia.query.Query;
import com.mongodb.Mongo;
import com.zzzzzz.account.model.Ticket;
import com.zzzzzz.core.dao.morphia.BaseDao;

public class TicketDao extends BaseDao<Ticket, String> {

	public TicketDao(Mongo mongo, Morphia morphia, String dbName) {
		super(mongo, morphia, dbName);
	}
	
	public void add(Ticket ticket) {
		save(ticket);
	}

	public Ticket findByKey(String key) {
		return findOne("key", key);
	}

	public Ticket findByKeyAndType(String key, String type) {
		Query<Ticket> query = createQuery();
		query.field("key").equal(key);
		query.field("type").equal(type);
		return findOne(query);
	}

	public void delByKey(String key) {
		Query<Ticket> query = createQuery();
		query.field("key").equal(key);
		deleteByQuery(query);
	}

}
